package com.net.shop.car.manager.ui;

import android.os.Bundle;
import android.os.Handler;

import com.net.shop.car.manager.App;
import com.net.shop.car.manager.BaseActivity;
import com.net.shop.car.manager.Constant;
import com.net.shop.car.manager.R;
import com.net.shop.car.manager.ui.user.LoginActivity;
import com.net.shop.car.manager.utils.StringAndDateUtils;

public class WelcomeAcitivity extends BaseActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				actionStart(MainActivity.class);
				finish();
			//	if (getBooleanFromSharedPreferences(Constant.sp.login_automatic)) {
					//doLogin();
			//	} else {
			actionStart(LoginActivity.class);
			//		finish();
				//}
			}
		}, 200);
	}

	protected void doLogin() {
		App.i().login(getStringFromSharedPreferences(Constant.sp.login_name), 
				getStringFromSharedPreferences(Constant.sp.password),
				StringAndDateUtils.nullStrToStr(getStringFromSharedPreferences(Constant.sp.android_user_id), ""), 
				StringAndDateUtils.nullStrToStr(getStringFromSharedPreferences(Constant.sp.channel_id), ""), 
				new App.OnLoginListener() {
					
					@Override
					public void onLogged() {
						actionStart(MainActivity.class);
						finish();
					}
					
					@Override
					public void onLoggFailed(String errorMsg) {
						actionStart(LoginActivity.class);
						finish();
					}
				});
	}
}
